// ignore_for_file: must_be_immutable

import 'package:aitao_flutter/greet/greet_image_page.dart';
import 'package:aitao_flutter/greet/greet_text_page.dart';
import 'package:aitao_flutter/greet/greet_voice_page.dart';
import 'package:aitao_flutter/style/text_style.dart';
import 'package:flutter/material.dart';

import '../const/common_const.dart';
import '../style/color_style.dart';
import '../style/radius_style.dart';

class ShowGreetSheetWidget extends StatefulWidget {
  ShowGreetSheetWidget(
      {super.key,
      required this.addCallback,
      required this.greetTextCallback,
      required this.greetImageCallback,
      required this.greetVoiceCallback});
  VoidCallback addCallback;
  Function(String) greetTextCallback;
  Function(int) greetImageCallback;
  Function(int) greetVoiceCallback;
  @override
  State<ShowGreetSheetWidget> createState() => _ShowGreetSheetWidgetState();
}

class _ShowGreetSheetWidgetState extends State<ShowGreetSheetWidget>
    with SingleTickerProviderStateMixin {
  late TabController tabController;
  final List<String> tabList = [
    MineStringConst.charactersText,
    MineStringConst.imageText,
    MineStringConst.audioText,
  ];
  int tabIndex = 0;
  @override
  void initState() {
    super.initState();
    tabController = TabController(length: 3, vsync: this, initialIndex: 0);
  }

  void addHelloText() {
    debugPrint('addHelloText');
  }

  @override
  Widget build(BuildContext context) {
    return Material(
        child: Container(
      decoration: BoxDecoration(
        color: ColorStyle.whiteColor,
        borderRadius: RadiusStyle.setPortionRadius(
            PortionRaduisType.radiusTopLeftAndTopRight, 16),
      ),
      height: 450,
      child: Column(
        children: [
          Container(
            height: 44,
            color: ColorStyle.whiteColor,
            child: TabBar(
              onTap: (i) {
                debugPrint(i.toString());
                setState(() {
                  tabIndex = i;
                });
              },
              isScrollable: true,
              labelColor: ColorStyle.normalTextColor,
              indicatorColor: ColorStyle.themeColor,
              indicatorSize: TabBarIndicatorSize.label,
              indicatorPadding: const EdgeInsets.only(left: 8, right: 8),
              indicatorWeight: 3,
              labelPadding: const EdgeInsets.only(bottom: 0),
              tabs: tabList.asMap().entries.map((e) {
                return Padding(
                    padding: const EdgeInsets.only(left: 8, right: 8),
                    child: Text(e.value,
                        style: e.key == tabIndex
                            ? Styles.normalText_16
                            : const TextStyle(
                                color: ColorStyle.normalTextColor,
                                fontSize: 15)));
              }).toList(),
              controller: tabController,
            ),
          ),
          Expanded(
              child: TabBarView(
            controller: tabController,
            children: [
              GreetTextPage(
                greetTextCallback: (txt) {
                  if (txt != '') {
                    widget.greetTextCallback(txt);
                  }
                  Navigator.pop(context);
                },
              ),
              GreetImagePage(
                greetImageCallback: (hiId) {
                  if (hiId != 0) {
                    widget.greetImageCallback(hiId);
                  }
                  Navigator.pop(context);
                },
              ),
              GreetVoicePage(
                greetVoiceCallback: (hiId) {
                  if (hiId != 0) {
                    widget.greetVoiceCallback(hiId);
                  }
                  Navigator.pop(context);
                },
                deleteVoiceCallback: (hiId) {
                  if (hiId != 0) {
                    widget.greetVoiceCallback(hiId);
                  }
                  Navigator.pop(context);
                },
              )
            ],
          )),
          Container(
            alignment: Alignment.center,
            height: 50,
            color: ColorStyle.whiteColor,
            child: GestureDetector(
              child: Text(
                ' +添加 ',
                style: Styles.mainText_16,
              ),
              onTap: () {
                Navigator.pop(context);
                widget.addCallback();
              },
            ),
          ),
        ],
      ),
    ));
  }
}
